#方法2 plot画图
x <- prostat;
colnames(x)[2] <- "log2fc"
x$log10p <- -log10(x$P)
fccutoff <- 1.2; #fc阈值
pcutoff <- 0.05; #p阈值
x$color <- "grey"
  pos = x$log2fc> log2(fccutoff) & x$P < pcutoff
  x$color[pos] <- "red" #把满足条件up的设置为red
    pos = x$log2fc< -log2(fccutoff) & x$P < pcutoff
    x$color[pos] <- "green" #把满足条件down的设置为green
      plot(x$log2fc, x$log10p, type = "n",
           main="volcano plot",xlab="log2FC",ylab="-log10(p)") #画空白图 确定x,y范围
      points(x$log2fc,x$log10p,col=x$color,pch=16,cex=1) #画点
      abline(v=c(-log2(fccutoff),log2(fccutoff)),lty=3) #画虚线
      abline(h=-log10(pcutoff),lty=3)  #画虚线
      legend("topright",c("up","nosig","down"),col = c("red","grey","green"),
             bty = "n", text.col ="black",
             pch = 16, cex= 0.6)  #画图注
      up <- subset(x,color == "red" & log2fc > 0.7) 
      text(up$log2fc,up$log10p+0.2,labels = up$ID, cex = 0.6) #log2fc >0.7的标记名字
      down <- subset(x,color == "green" & log2fc < -0.7) 
      text(down$log2fc,down$log10p+0.2,labels = down$ID, cex = 0.6) #log2fc <-0.7的标记名字
      
      #存图需要重新输入一遍
      jpeg("volcano.jpg",width =8, height = 6, units = "in",res = 300) #设置宽高,单位和分辨率
      plot(x$log2fc, x$log10p, type = "n",
           main="volcano plot",xlab="log2FC",ylab="-log10(p)") #画空白图 确定x,y范围
      points(x$log2fc,x$log10p,col=x$color,pch=16,cex=1) #画点
      abline(v=c(-log2(fccutoff),log2(fccutoff)),lty=3) #画虚线
      abline(h=-log10(pcutoff),lty=3)  #画虚线
      legend("topright",c("up","nosig","down"),col = c("red","grey","green"),
             bty = "n", text.col ="black",
             pch = 16, cex= 0.6)  #画图注
      up <- subset(x,color == "red" & log2fc > 0.7) 
      text(up$log2fc,up$log10p+0.2,labels = up$ID, cex = 0.6) #log2fc >0.7的标记名字
      down <- subset(x,color == "green" & log2fc < -0.7) 
      text(down$log2fc,down$log10p+0.2,labels = down$ID, cex = 0.6) #log2fc <-0.7的标记名字
      graphics.off()